package cn.example.web.db.bean;

import lombok.experimental.Accessors;
import lombok.Data;
import lombok.AccessLevel;
import lombok.Setter;
import java.util.Date;
import org.artifact.core.db.BaseBean;
import org.artifact.core.lang.IServer;
import java.util.Map;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.map.MapUtil;
import java.util.HashMap;
@Data
@Accessors(chain = true)
@SuppressWarnings({"rawtypes","unchecked"})
/** 服务器 */
public abstract class Server implements BaseBean<Server> {
	/** 主键 */
	private long id;
	/** 服务器名称 */
	private String name;
	/** 标记:0.默认 1.推荐  2.新服  3.火爆   */
	private int tag;
	/** 状态:0.未激活 1.激活  2.维护  3.运行   */
	private int status;
	/** 最小客户端版本号 */
	private String minClientVersion;
	/** 最大客户端版本号 */
	private String maxClientVersion;
	/** 创建时间 */
	@Setter(value = AccessLevel.PROTECTED)
	private java.util.Date createDate;
	/** 修改时间 */
	@Setter(value = AccessLevel.PROTECTED)
	private java.util.Date modifiedDate;
	
	


	


	@Override
	public Server deepCopy() {
		Server server = null;
		try {
			server = (Server) super.clone();
			server.createDate = (java.util.Date)this.createDate.clone();
			server.modifiedDate = (java.util.Date)this.modifiedDate.clone();
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		onCopy(server);
		return server;
	}

	public <T extends Server> T build(Server t){
	    if(t == null) return null;
	    BeanUtil.copyProperties(t, this);
        onRead();
        return (T)this;
	}

	public Server toSave() {
		Date now = new Date();
		if (createDate==null) {
			createDate = now;
			modifiedDate = now;
		}else {
			modifiedDate = now;
		}
		onWrite();
		return deepCopy();
	}
	


    /**
     * 写数据
     */
    public Object write(){
        Object[] values = new Object[8];
        values[0] = this.id;
        values[1] = this.name;
        values[2] = this.tag;
        values[3] = this.status;
        values[4] = this.minClientVersion;
        values[5] = this.maxClientVersion;
        values[6] = this.createDate;
        values[7] = this.modifiedDate;
        return values;
    }

    /**
     * 读数据
     */
    public Server read(Object object){
        Object[] array = (Object[])object;
        this.id = (long)array[0];
        this.name = (String)array[1];
        this.tag = (int)array[2];
        this.status = (int)array[3];
        this.minClientVersion = (String)array[4];
        this.maxClientVersion = (String)array[5];
        this.createDate = (java.util.Date)array[6];
        this.modifiedDate = (java.util.Date)array[7];
        return this;
    }
    /**
     * 克隆之后
     */
    protected void onCopy(Server server){

    }

    /**
     * 写数据之前
     */
    protected void onWrite(){
    }

    /**
     * 读数据之后
     */
    protected void onRead(){
    }

	@Override
	public Object pk() {
		return this.id;
	}
}